package com.nbcio.modules.erp.voucher.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nbcio.modules.erp.voucher.domain.ErpAccountConfig;
import com.nbcio.modules.erp.voucher.mapper.ErpAccountConfigMapper;
import com.nbcio.modules.erp.voucher.service.IErpAccountConfigService;
import org.springframework.stereotype.Service;

/**
 * 科目配置服务实现
 */
@Service
public class ErpAccountConfigServiceImpl extends ServiceImpl<ErpAccountConfigMapper, ErpAccountConfig> 
        implements IErpAccountConfigService {

    @Override
    public Long getAccountId(String billType, String entryType) {
        ErpAccountConfig config = getConfig(billType, entryType);
        return config != null ? config.getAccountId() : null;
    }

    @Override
    public ErpAccountConfig getConfig(String billType, String entryType) {
        return this.getOne(new LambdaQueryWrapper<ErpAccountConfig>()
                .eq(ErpAccountConfig::getBillType, billType)
                .eq(ErpAccountConfig::getEntryType, entryType)
                .eq(ErpAccountConfig::getStatus, 1)
                .orderByDesc(ErpAccountConfig::getPriority)
                .last("LIMIT 1"));
    }
}

